import os
from PIL import Image
from tqdm import tqdm
from glob import glob

def png2jpg(input, remove_flag=False):
    if input[-4:] != '.png':
        print("sorry, it's not a png file")
        return
    output = input[:-4]+'.jpg'
    img = Image.open(input)
    img = img.convert("RGB")
    img.save(output)
    if remove_flag:
        os.remove(input)

fdirs = glob('imp_datasets/video_datasets/data/kinetics/flow_l8/**/*png', recursive=True) # 列出glob的子文件夹里面的所有jpg图片（不包含glob下的jpg文件）
for i in tqdm(fdirs):
    png2jpg(i)